home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / SoundClass.cp < prev    next >
Encoding:
Text File  |  1993-01-14  |  2.1 KB  |  77 lines  |  [TEXT/MPS ]

  1. // Sound.cp
  2.  
  3. /* _________________________________________________________________________________________________________ //
  4.   Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
  5.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  6.   Programmer: Kent Sandvik
  7.   Date: 12/21/92
  8.   Revision comments are at the end of this file.
  9.   ---
  10.   TSound is a simple object that plays sounds     
  11.   TSound.cp contains the TSound member functions. 
  12.   _________________________________________________________________________________________________________ */
  13.  
  14. #ifndef _SOUND_
  15. #include "SoundClass.h"
  16. #endif
  17.  
  18.  
  19. // CONSTRUCTORS AND DESTRUCTORS
  20. #pragma segment Sound
  21. TSound::TSound(char* name)
  22. // Construct the TSound class using the string name for the sound resource.
  23. {
  24.     strcpy(fSound, name);
  25.     c2p(fSound);                                // convert it to a Pascal string
  26.  
  27.     fSoundHandle = ::GetNamedResource(kSoundType, (ConstStr255Param)fSound);// get the resource
  28.     ASSERT(fSoundHandle != NULL, "\pDidn't find the Sound Resource");
  29.     if (fSoundHandle != NULL)
  30.         ::DetachResource(fSoundHandle);            // detach it so we could have multiple copies in memory
  31. }
  32.  
  33.  
  34. TSound::TSound(short resID)
  35. // Construct the TSound class using a resource ID.
  36. {
  37.     fSoundID = resID;
  38.     fSoundHandle = ::GetResource(kSoundType, fSoundID);
  39.     ASSERT(fSoundHandle != NULL, "\pDidn't find the Sound Resource");
  40.     if (fSoundHandle != NULL)
  41.         ::DetachResource(fSoundHandle);            // detach it so we could have multiple copies in memory
  42. }
  43.  
  44.  
  45. #pragma segment Sound
  46. TSound::~TSound()
  47. // Destruct the sound handle.
  48. {
  49.     if (fSoundHandle != NULL)                    // we have a valid snd handle
  50.     {
  51.         ::DisposeHandle(fSoundHandle);
  52.     }
  53. }
  54.  
  55.  
  56. // MAIN INTERFACE
  57. #pragma segment Sound
  58. void TSound::Play()
  59. // Play the selected sound.
  60. {
  61.     if (fSoundHandle != NULL)                    // we have a valid snd handle
  62.     {
  63.         fError = ::SndPlay(NULL, fSoundHandle, false);// play synchronously
  64.         VASSERT(fError == noErr, ("Problems with SndPlay = %d\n", fError));
  65.     }
  66. }
  67.  
  68.  
  69. // _________________________________________________________________________________________________________ //
  70.  
  71.  
  72. /*    Change History (most recent last):
  73.   No        Init.    Date        Comment
  74.   1            khs        12/21/92    New file
  75.   2            khs        1/14/93        Cleanup
  76. */
  77.